package test;

import util.DruidUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @Author:
 * @Date: 2020/2/7
 * @Description: @PACKAGE:dao.login
 * @version: 1.0
 */
public class FindPwd {
    Boolean flag = false;

    /**
     * 功能描述:通过医生id登录时验证密码
     *
     * @param: LoginId ,LoginPwd
     * @return: flag=true/flag=false
     * @Author:
     * @date: 2020/2/7 23:08
     */
    public Boolean FindPwdByDoctorId(String LoginId, String LoginPwd) throws Exception {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            conn = DruidUtils.getConnection();
            String sql = "SELECT D_pwd FROM t_doctor WHERE D_id=? ";
            ps = conn.prepareStatement(sql);
            ps.setString(1, LoginId);
            rs = ps.executeQuery();
            if (rs.next()) {
                String pwd = rs.getString(1);
                if (LoginPwd.equals(pwd)) {
                    flag = true;
                }
            }
        } finally {
            DruidUtils.closeAll(rs, ps, conn);
        }
        return flag;
    }

    /**
     * 功能描述:功能描述:通过医生Tel登录时验证密码
     *
     * @param: LoginId ,LoginPwd
     * @return: flag=true/flag=false
     * @Author:
     * @date: 2020/2/7 23:31
     */
    public Boolean FindPwdByDoctorTel(String LoginId, String LoginPwd) throws Exception {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            conn = DruidUtils.getConnection();
            String sql = "SELECT D_pwd FROM t_doctor WHERE D_Tel=? ";
            ps = conn.prepareStatement(sql);
            ps.setString(1, LoginId);
            rs = ps.executeQuery();
            if (rs.next()) {
                String pwd = rs.getString(1);
                if (LoginPwd.equals(pwd)) {
                    flag = true;
                }
            }
        } finally {
            DruidUtils.closeAll(rs, ps, conn);
        }
        return flag;
    }

    /**
     * 功能描述:通过病人id登录时验证密码
     *
     * @param: LoginId ,LoginPwd
     * @return: flag=true/flag=false
     * @Author:
     * @date: 2020/2/7 23:40
     */
    public Boolean FindPwdByPatientId(String LoginId, String LoginPwd) throws Exception {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            conn = DruidUtils.getConnection();
            String sql = "SELECT P_pwd FROM t_patient WHERE P_id=? ";
            ps = conn.prepareStatement(sql);
            ps.setString(1, LoginId);
            rs = ps.executeQuery();
            if (rs.next()) {
                String pwd = rs.getString(1);
                if (LoginPwd.equals(pwd)) {
                    flag = true;
                }
            }
        } finally {
            DruidUtils.closeAll(rs, ps, conn);
        }
        return flag;
    }

    /**
     * 功能描述:通过病人Tel登录时验证密码
     *
     * @param: LoginId ,LoginPwd
     * @return: flag=true/flag=false
     * @Author:
     * @date: 2020/2/7 23:45
     */
    public Boolean FindPwdByPatientTel(String LoginId, String LoginPwd) throws Exception {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            conn = DruidUtils.getConnection();
            String sql = "SELECT P_pwd FROM t_patient WHERE P_Tel=? ";
            ps = conn.prepareStatement(sql);
            ps.setString(1, LoginId);
            rs = ps.executeQuery();
            if (rs.next()) {
                String pwd = rs.getString(1);
                if (LoginPwd.equals(pwd)) {
                    flag = true;
                }
            }
        } finally {
            DruidUtils.closeAll(rs, ps, conn);
        }
        return flag;
    }

    /**
     * 功能描述:通过病人家属Id登录时验证密码
     *
     * @param: LoginId ,LoginPwd
     * @return: flag=true/flag=false
     * @Author:
     * @date: 2020/2/8 0:15
     */
    public Boolean FindPwdByFamilyId(String LoginId, String LoginPwd) throws Exception {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            conn = DruidUtils.getConnection();
            String sql = "SELECT F_pwd FROM t_family WHERE F_id=? ";
            ps = conn.prepareStatement(sql);
            ps.setString(1, LoginId);
            rs = ps.executeQuery();
            if (rs.next()) {
                String pwd = rs.getString(1);
                if (LoginPwd.equals(pwd)) {
                    flag = true;
                }
            }
        } finally {
            DruidUtils.closeAll(rs, ps, conn);
        }
        return flag;
    }

    /**
     * 功能描述:通过病人家属Tel登录时验证密码
     *
     * @param: LoginId ,LoginPwd
     * @return: flag=true/flag=false
     * @Author:
     * @date: 2020/2/8 0:25
     */
    public Boolean FindPwdByFamilyTel(String LoginId, String LoginPwd) throws Exception {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            conn = DruidUtils.getConnection();
            String sql = "SELECT F_pwd FROM t_family WHERE F_tel=? ";
            ps = conn.prepareStatement(sql);
            ps.setString(1, LoginId);
            rs = ps.executeQuery();
            if (rs.next()) {
                String pwd = rs.getString(1);
                if (LoginPwd.equals(pwd)) {
                    flag = true;
                }
            }
        } finally {
            DruidUtils.closeAll(rs, ps, conn);
        }
        return flag;
    }

}
